package com.dreem.principle.inversion.improve;

/**
 * @program: DesignParrtern
 * @description:
 * @author: Peng
 * @create: 2021-01-16  09:57
 **/
public class DependencyInversionUP02 {
    public static void main(String[] args){
        ITV02 tv = new ITV02() {
            @Override
            public void play() {
                System.out.println("CCTV6正在播放!");
            }
        };
        new OpenAndClose02(tv).open();
    }
}

// 方式2:通过构造方法依赖传递
interface IOpenAndClose02{
    public void open();// 抽象方法
}

interface ITV02{ // ITV接口
    public void play();
}

class OpenAndClose02 implements IOpenAndClose02 {
    private ITV02 tv;

    public OpenAndClose02(ITV02 tv){
        this.tv = tv;
    }
    @Override
    public void open() {
        this.tv.play();
    }
}